<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
date_default_timezone_set("PRC"); //timezone

$db1=mysql_connect("localhost","root","root"); 
mysql_select_db('faithwar',$db1); 

$db2=mysql_connect('192.168.0.17','root','root'); 
mysql_select_db('faithwar',$db2); 

#$dateTime = date("Y-m-d",strtotime("-2 day"));
$dateTime = date("Y-m-d");
//$dateTime = '2012-08-09';

    $deviceid_query = mysql_query("select  deviceid,level,cities from tbheartbeat_last_temp where date = '$dateTime'",$db2); //id


while($deviceid = mysql_fetch_array($deviceid_query))
{

    //$money_query = mysql_query("SELECT sum(money) from tbiap where date = '$dateTime' and deviceid= '$deviceid[deviceid]'",$db2);
    //$money = mysql_fetch_array($money_query);
   //var_dump($money[0]);

     $sql = "UPDATE  faithwar_query_temp SET level= '$deviceid[level]',cities= '$deviceid[cities]' WHERE deviceid= '$deviceid[deviceid]' and  date ='$dateTime'";
     
   if(mysql_query($sql,$db1)){
    echo "1 update is ok!";
} else {
    echo "failed".mysql_error();
}

}

// mysql_query("update faithwar a1 inner join deviceid a2 using(deviceid) set a1.firstlogindata =a2.firstlogindata where a1.deviceid =  a2.deviceid");
mysql_close($db1);
mysql_close($db2);
?>